package com.alibaba.travel.thirdpart.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.alibaba.travel.common.model.dto.TopicLikesCountResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.alibaba.travel.thirdpart.entity.UserLikesRecordEntity;
import com.alibaba.travel.thirdpart.service.UserLikesRecordService;
import com.alibaba.travel.common.utils.PageUtils;
import com.alibaba.travel.common.utils.R;



/**
 * 用户点赞记录表
 *
 * @author wherezy
 * @email wherezy@tom.com
 * @date 2023-03-06 14:49:51
 */
@Api(tags = {"用户点赞记录表"})
@RestController
@RequestMapping("likes/userlikesrecord")
public class UserLikesRecordController {
    @Autowired
    private UserLikesRecordService userLikesRecordService;


    @ApiOperation(value = "通过topicId，查询点赞数")
    @PostMapping("/getLikes")
    public R getLikesNumber(@RequestBody Long[] topicIds) {
        List<TopicLikesCountResponse> list = userLikesRecordService.getLikesNumber(topicIds);

        return R.ok().put("list", list);
    }

    /**
     * 用户通过id查询当前状态
     * @return
     */
    @ApiOperation(value = "已登录用户，通过用户id获取点赞状态")
    @PostMapping("/status")
    public R getStatus(String topicType) {
        List<UserLikesRecordEntity> statusList = userLikesRecordService.getStatus(topicType);

        return R.ok().put("status", "statusList");
    }


    /**
     * 列表
     */
    @ApiOperation(value="用户分页获取点赞记录--需要TopicType参数", notes="k-v map形式封装分页参数")
    @PostMapping("/list")
    public R list(@RequestBody Map<String, Object> params){
        PageUtils page = userLikesRecordService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation(value="获取信息")
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		UserLikesRecordEntity userLikesRecord = userLikesRecordService.getById(id);

        return R.ok().put("userLikesRecord", userLikesRecord);
    }

    /**
     * 保存
     */
    @ApiOperation(value="保存")
    @PostMapping("/save")
    public R save(@RequestBody UserLikesRecordEntity userLikesRecord){
		userLikesRecordService.save(userLikesRecord);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value="修改")
    @PostMapping("/update")
    public R update(@RequestBody UserLikesRecordEntity userLikesRecord){
		userLikesRecordService.updateById(userLikesRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value="删除")
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		userLikesRecordService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
